package com.schedule.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.schedule.Util.PagedGridResult;
import com.schedule.mapper.JudgeMapper;
import com.schedule.pojo.Judge;
import com.schedule.service.IJudgeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author star
 * @since 2022-03-08
 */
@Service
public class JudgeServiceImpl extends ServiceImpl<JudgeMapper, Judge> implements IJudgeService {
    @Autowired
    private JudgeMapper judgeMapper;

    /**
     * 直接查找所有裁判
     */
    public List<Judge> findAll(){
        return judgeMapper.findAll();
    }

    /**
     * 分页查询裁判
     */
    public PagedGridResult findJudge(Integer page, Integer pageSize){
        PageHelper.startPage(page, pageSize);
        List<Judge> judges = judgeMapper.findJudge();
        PagedGridResult gridResult = PagedGridResult.setterPagedGrid(judges, page);
        return gridResult;
    }

    /**
     * 新建一个裁判
     */
    @Override
    public boolean setJudge(String Name, String Other, Integer Aid) {
        if (judgeMapper.setJudge(Name, Other, Aid)!=0){
            return true;
        }
        return false;
    }

    /**
     * 删除裁判
     *
     * @param Jid
     * @return
     */
    @Override
    public int delJudge(Integer Jid) {
        int i = judgeMapper.delJudge(Jid);
        return i;
    }
//    @Override
//    public int delJudge(Integer Jid) {
//        int i = judgeMapper.deleteById(Jid);
//        return i;
//    }

    /**
     * 修改赛事中的裁判
     *
     * @param Jid
     */
    @Override
    public boolean updateJudge(Integer Jid, String CName) {
        if (judgeMapper.updateJudge(Jid, CName)!=0){
            return true;
        }
        return false;
    }

    /**
     * 根据Jid查找裁判
     *
     * @param Jid
     * @return
     */
    @Override
    public Judge findJudgeByJid(Integer Jid) {
        return judgeMapper.selectOne(new QueryWrapper<Judge>()
                .eq("JId",Jid));
    }

}
